package cn.tedu.flinkbasic.dataset;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.operators.MapOperator;
import org.apache.flink.util.Collector;

/**
 * DataSetHello
 */
public class DataSetDemo {
    public static void main(String[] args) throws Exception {
        //1.获取执行环节
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        //2.获取数据源
        DataSource<String> source = env.fromElements("http://localhost/b.jsp|b.jsp" +
                "|页面B|UTF-8|1280x720|24-bit|zh-cn|0|1||0.17773500245502682|http://local" +
                "host/a.jsp|Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
                "(KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36|989355347906233852" +
                "19|9938268420_40_1598579046684|0:0:0:0:0:0:0:1");
        //3.数据转换(计算:DAG)
        source.flatMap(new FlatMapFunction<String, String>() {
            @Override
            public void flatMap(String value, Collector<String> out) throws Exception {
                String[] split = value.split("\\|");
                for (String s : split) {
                    out.collect(s);
                }
            }
        })
                //4.输出结果
                .print();
        //5.触发执行
        //本案例不需要
    }
}
